package com.situ.yB2C.cart.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.situ.yB2C.cart.pojo.Cart;
import com.situ.yB2C.cart.service.CartService;
import com.situ.yB2C.util.ContextUtil;

@Controller
@RequestMapping("/cart/")
public class CartController {
	
	@Autowired
	private CartService cartService;
	
	@ResponseBody
	@RequestMapping("doadd")
	public int doAddCart(Cart cart , HttpSession session) {
		//得到登录的买家的用户的ID
		Long userId = ContextUtil.getBuyerUserId(session);
		return cartService.doaddCart(cart, userId, session);
	}
	//右上角购物车 
//	@ResponseBody
//	@RequestMapping("info")
//	public ModelAndView findCartListBySession(HttpSession session,ModelAndView modelAndView){
//		Object object=session.getAttribute(ContextUtil.SESSION_LOGIN_BUYER);
//		if (object !=null) {
//			modelAndView.addObject("cartList", (List<Cart>)object);
//		}
//		modelAndView.setViewName("shop/mini-cart");
//		return modelAndView;
//	}
	//购物车
	@ResponseBody
	@RequestMapping("info1")
	public ModelAndView findTotalCartListBySession(HttpSession session,ModelAndView modelAndView){
		Object object=session.getAttribute(ContextUtil.SESSION_CART_NAME);
		if (object !=null) {
			modelAndView.addObject("cartList", (List<Cart>)object);
		}
		modelAndView.setViewName("shop/total_cart");
		return modelAndView;
	}
	
	//产品详情
	
	
	
	
	
	
	
	
	
	
	
	
}
